#ifndef _DEF_H
#define _DEF_H

#include "public_def.h"


#define FREE_C(a) free((a)); a = NULL; 



#if 0
#define atoi(a)		a ? atoi(a) : 0
#define strlen(a) 	a ? strlen(a) : 0
#endif


#ifdef DEBUG_MEM
struct mem_trace_t
{
	char func_name[128][128];
	int call_line[128];
	void *address[128];
	int size[128];
	int trace_cnt;
	int index;
}mem_trace;

extern struct mem_trace_t mem_trace;

#define malloc(a)		mem_trace.address[mem_trace.trace_cnt] = malloc(a);\
						printf("%s call malloc : address is 0x%x size is %d\n", __func__, (int)mem_trace.address[mem_trace.trace_cnt], a);\
						strcpy(mem_trace.func_name[mem_trace.trace_cnt], __func__);\
						mem_trace.size[mem_trace.trace_cnt] = a;\
						mem_trace.call_line[mem_trace.trace_cnt] = __LINE__;\
						if(mem_trace.trace_cnt > 126)\
						{\
							mem_trace.trace_cnt = 0;\
						}\
						else\
						{\
							mem_trace.trace_cnt++;\
						}
								
#define free(a)			free(a);\
						printf("free address is 0x%x mem_trace.trace_cnt is %d\n", (int)a, mem_trace.trace_cnt);\
						if((mem_trace.trace_cnt > 0) && (a != NULL))\
						{\
							for(mem_trace.index = 0; mem_trace.index < mem_trace.trace_cnt; mem_trace.index++)\
							{\
								if(a == mem_trace.address[mem_trace.index])\
								{\
									for(; mem_trace.index < mem_trace.trace_cnt - 1; mem_trace.index++)\
									{\
										strcpy(mem_trace.func_name[mem_trace.index], mem_trace.func_name[mem_trace.index + 1]);\
										mem_trace.call_line[mem_trace.index] = mem_trace.call_line[mem_trace.index + 1];\
										mem_trace.address[mem_trace.index] = mem_trace.address[mem_trace.index + 1];\
										mem_trace.size[mem_trace.index] = mem_trace.size[mem_trace.index + 1];\
									}\
								}\
							}\
							mem_trace.trace_cnt--;\
						}\
						a = NULL;

#endif


#define _CAT(a, b)          a##b
#define CAT(a, b)           _CAT(a, b)                

#define MULTICAST_ADDR       "239.255.255.250"

#define INSTANCE_ID          0
#define MESSAGE_NUM          1
#define METADATA_VER         2

#define ADD_CONF          	1
#define REPLACE_CONF      	2
#define RM_CONF           	3

#define OK            		0
#define ERROR 				-1
#define EXIST				-2
#define NOT_EXIST         	-3
#define PERMISSION_DENIED   -4

#define INT_LEN		12

#define TIMEOUT		15
#define CRLF "\r\n"

enum 
{
	G711a = 1,
	G711u,
	ADPCM
};

#endif

